<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <!-- basic styles -->
        <link href="../assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="../assets/css/font-awesome.min.css" />
        <link rel="stylesheet" href="../assets/css/ace.min.css" />
        <link rel="stylesheet" href="../assets/css/ace-rtl.min.css" />
        <link rel="stylesheet" href="../assets/css/ace-skins.min.css" />
        <style type="text/css">
            .dialog_textarea{
                width: 98%;
                height:150px;
                padding: 1%;
            }

        </style>
    </head>
    <body>
        <div class="main-container">
            <div class="col-xs-12">
                <h3 class="header smaller lighter blue">策略下发队列</h3>
                <div style="padding-bottom: 5px;">
                    <button class="btn btn-success issued" onclick="issued()">策略下发</button>
                </div>
                <div class="table-header">
                    策略下发队列信息
                </div>
                <div class="table-responsive">
                    <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th>id</th>
                                <th>DPI名称</th>
                                <th>DPI地址</th>
                                <th>策略类型</th>
                                <th>策略ID</th>
                                <th>入列时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">选择设备</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal">
                            <div class=" row box">
                                <!--                                <div class="checkbox col-xs-4">
                                                                    <label>
                                                                        <input type="checkbox" class="ace" checked name="form-field-checkbox">
                                                                        <span class="lbl"> choice 1</span>
                                                                    </label>
                                                                </div>-->
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <a href="javascript:void(0)" class="btn btn-default" data-dismiss="modal">取消</a>
                        <a href="javascript:void(0)" class="btn btn-primary addIssuedList">确定</a>
                    </div>
                </div>
            </div>
        </div>
        <script src="../assets/js/jquery.js"></script>
        <script src="../assets/js/bootstrap.min.js"></script>
        <!-- page specific plugin scripts -->
        <script src="../assets/js/jquery-ui-1.10.3.custom.min.js"></script>
        <script src="../assets/js/jquery.dataTables.min.js"></script>
        <script src="../assets/js/jquery.dataTables.bootstrap.js"></script>
        <script src="../assets/js/Base64.js"></script>
        <script type="text/javascript">
                        var base64 = new Base64();
                        function issued() {
                            $(".issued").attr("disabled", "");
                            $.ajax({
                                type: "GET",
                                async: false,
                                url: "../action/policy/send_policy_ucagent.do",
                                data: {},
                                dataType: "json",
                                success: function(data) {
                                    if (data.result == "true") {
                                        alert("下发成功!");
                                        window.location.reload();
                                    } else {
                                        alert("下发失败")
                                    }
                                }
                            });
                            $(".issued").removeAttr("disabled")
                        }
                        function getIssuedAll() {
                            var obj;
                            $.ajax({
                                type: "GET",
                                async: false,
                                url: "../messagequeue/list",
                                data: {},
                                dataType: "json",
                                success: function(data) {
                                    obj = data;
                                }
                            });
                            return obj;
                        }
                        function getPolicyLibrary() {
                            var obj;
                            $.ajax({
                                type: "GET",
                                async: false,
                                url: "../assets/data/PolicyLibrary_2.json",
                                data: {},
                                dataType: "json",
                                success: function(data) {
                                    obj = data;
                                }
                            });
                            return obj;
                        }
                        function trMessageType(type) {
                            return messageTypeAll[type];
                        }
                        function delPolicy(id) {
                            $.ajax({
                                type: "GET",
                                async: false,
                                url: "../messagequeue/delete",
                                data: {id: id},
                                dataType: "json",
                                success: function(data) {
                                    if (data.result == "true") {
                                        alert("已剔除该策略!");
                                        window.location.reload();
                                    } else {
                                        alert("剔除失败")
                                    }
                                }
                            });
                        }
                        var messageTypeAll = getPolicyLibrary();
                        ;
                        jQuery(function($) {
                            var souData = getIssuedAll();
                            var aaData = [];
                            for (var i in souData) {
                                var id = souData[i].id;
                                var dpi = souData[i].dpi;
                                var ip = souData[i].ip;
                                var messageType = trMessageType(souData[i].messageType);
                                var messageNo = souData[i].messageNo;
                                var time = souData[i].time;
                                var oper = '';
                                oper += "<a class='blue' href='javascript:void(0)' onclick=getStrategyDetail(" + id + ") title='查看' '>";
                                oper += "    <i class='icon-pencil bigger-130'></i>";
                                oper += "</a>";
                                oper += "<a class='red' href='javascript:void(0)' title='剔除策略' onclick='delPolicy(" + id + ")'>";
                                oper += "    <i class='icon-trash bigger-130'></i>";
                                oper += "</a>";
                                aaData.push([id, dpi, ip, messageType, messageNo, time, oper]);
                            }
                            var oTable1 = $('#sample-table-2').dataTable({
                                "aoColumns": [
                                    {"bSortable": true},
                                    {"bSortable": false},
                                    {"bSortable": false},
                                    {"bSortable": false},
                                    {"bSortable": false},
                                    {"bSortable": false},
                                    {"bSortable": false}
                                ],
                                "aaData": aaData
                            });
                            setInterval(function() {
                                parent.$("#page-content").attr("height", $("html").height());
                            }, 500);
                        });


                        function getStrategyDetail(id) {
                            $.post("../message/util/messagesendingqueueview", {logId: id}, function(data) {
                                openDialog(data);
                            }, "json");
                        }
                        //添加查看策略弹窗
                        function openDialog(data) {
                            closeDialog();
                            var cont = '';
                            cont += "<div id='modal-wizard' class='modal'>";
                            cont += "            <div class='modal-dialog'>";
                            cont += "                <div class='modal-content'>";
                            cont += "                    <div class='modal-header' data-target='#modal-step-contents'>";
                            cont += "                        <h3>查看策略内容</h3>";
                            cont += "                    </div>";
                            cont += "                    <div class='modal-body step-content' id='modal-step-contents'>";
                            cont += "                        <div class='' id='modal-step1'>";
                            cont += "                            <div class='center'>";
                            cont += "                                <form class='form-horizontal'>";
                            cont += "                                    <div class='form-group'>";
                            //cont += "                                        <label for='Dev_Name' class='col-sm-3 control-label no-padding-right'>查看策略内容</label>";
                            cont += "                                            <textarea class='dialog_textarea' readonly>" + data.bin + "</textarea>";
                            cont += "                                            <textarea class='dialog_textarea' readonly>" + base64.decode(data.json) + "</textarea>";
                            cont += "                                    </div>";
                            cont += "                                </form>";
                            cont += "                            </div>";
                            cont += "                        </div>";
                            cont += "                    </div>";
                            // cont += "                    <div class='modal-footer wizard-actions'>";
                            // cont += "                        <button class='btn btn-success btn-sm btn-next save' data-last='完成 ' onclick='saveGroup()'>";
                            // cont += "                            完成";
                            // cont += "                            <i class='icon-ok'></i>";
                            // cont += "                        </button>";
                            // cont += "                        <button class='btn btn-danger btn-sm pull-left' data-dismiss='modal'>";
                            // cont += "                            <i class='icon-remove'></i>";
                            // cont += "                            取消";
                            // cont += "                        </button>";
                            // cont += "                    </div>";
                            cont += "                </div>";
                            cont += "            </div>";
                            cont += "        </div>";
                            $("body").append(cont);

                            $('#modal-wizard').modal("show");
                        }

                        //关闭用户组弹窗
                        function closeDialog() {
                            $('#modal-wizard').modal("hide");
                            $('#modal-wizard').remove();
                        }



        </script>
    </body>
</html>
